package com.letoken.platform.repo.app.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.repo.admin.req.user.FundRecordReq;
import com.letoken.platform.repo.app.po.AppFundV2Info;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 作者
 * @since 2024-02-18
 */
public interface AppFundV2InfoMapper extends BaseMapper<AppFundV2Info> {
    @Select("select * from app_fund_v2_info where user_id = #{userId} for update")
    AppFundV2Info selectForUpdate(@Param("userId") Integer userId);

    @Select("select * from app_fund_v2_info where user_id = #{userId} ")
    AppFundV2Info selectBYUserId(@Param("userId") Integer userId);

    @Select("select * from app_fund_v2_info where retained >= #{amount}")
    List<AppFundV2Info> getFundV2List(@Param("amount")BigDecimal amount);

    @Select("select * from app_fund_v2_info where give >= #{amount}")
    List<AppFundV2Info> getFundV2GiveList(@Param("amount")BigDecimal amount);

    @Select("select 1 from  app_fund_v2_info where user_id = #{userId}")
    Integer existsFund(@Param("userId") Integer userId);




    @Select("select ifnull(sum(fund),0) from app_fund_v2_info")
    BigDecimal sumFund();

    @Select("select ifnull(sum(retained),0) from app_fund_v2_info")
    BigDecimal sumRetained();

    @Select("select ifnull(sum(fund),0) from app_fund_v2_info where date(create_time) = #{date}")
    BigDecimal sumFundByDate(LocalDate date);


    @Select("select ifnull(sum(fund),0) from app_fund_v2_info where create_time >= #{startDatetime} and  create_time <= #{endDatetime}")
    BigDecimal sumFundByCreateTime(@Param("startDatetime") LocalDateTime startDatetime,@Param("endDatetime")  LocalDateTime endDatetime);


    Page<AppFundV2Info> page(@Param("page") Page<AppFundV2Info> page, @Param("params") FundRecordReq params);
}
